package com.jk.vehicle.mini.schedule;

import com.jk.vehicle.mini.schedule.components.MileageStatistics;
import com.jk.vehicle.mini.service.CorpService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 生成统计图标定时器
 */
@Slf4j
@Component
public class ProjectSchedule {
    @Resource
    private MileageStatistics mileageStatistics;

    @Resource
    private CorpService corpService;

    /**
     * 每天执行一次
     */
     @Scheduled(cron = "0 0 1 * * ?")
//   @Scheduled(fixedRate = 1200000)
    public void oneDaySchedule(){
        log.info("---------------执行每日凌晨一点定时器：{} --------------", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
         List<String> dsNameList = corpService.selectAllCorpDsNameList();
         dsNameList.forEach(dsName -> {
             mileageStatistics.dayMileageStatistics(null, dsName);
             mileageStatistics.weekMileageStatistics(null, dsName);
             mileageStatistics.moonMileageStatistics(null, dsName);
         });
    }
}
